﻿@model WebApp.Models.S_dict
@{
    ViewBag.Title = CSMSLang.Get("label_selection_data_dictionary");
    Layout = "~/Views/Shared/_DialogLayout.cshtml";
}

 <div class="dialog-content">
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
     <div class="form-horizontal">
         <ul class="wysihtml5-toolbar">
             <li class="toolbar-right">
                 <div class="input-append input-icon-prepend">
                     <div class="add-on">
                         <a title="search" class="icon"><i class="icofont-search"></i></a>
                         <input type="text" id="searchkey" data-fieldname="searchkey" placeholder=@CSMSLang.Get("public_sub-project")>
                     </div>
                     <button id="btnquery" class="btn">@CSMSLang.Get("btn_search")@*查询*@</button>
                 </div>
             </li>
         </ul>
     </div>
     <div id="cc" class="easyui-layout" style="width:100%;height:320px;">
         <div region="west" split="true" title=@CSMSLang.Get("public_dictionary_type") style="width:200px;">
             <ul id="tabletree"></ul>
         </div>
         <div region="center" style="border:0;">
             <table id="datagrid"></table>
         </div>
     </div>
</div>
<div class="dialog-footer">
    <button id="btnclose" class="btn btn-default">@CSMSLang.Get("btn_close")@*关闭*@</button>
    <button id="btnok" class="btn btn-primary">@CSMSLang.Get("btn_ok")@*确定*@</button>
</div>

    @section scripts{
        <script type="text/javascript">
            //回调函数
            var callback = "@ViewBag.CallBack";
            //是否单选
            var singleselect = @(ViewBag.SingleSelect ? "true" : "false");

            var tableJson =@Html.Raw(ViewBag.TableTreeJson);
            var typecode = "";
            var isdelete="1";
            //列定义
            var cols = [[
         { field: "Id", title: 'Id', width: 10, hidden: true },
         { field: "ck", title: '', width: 20, checkbox: true },
         { field: "Sort", title:csms_lang.public_sort, sortable: true, width: 40, align: 'center' ,hidden: true },// '顺序'
         { field: "Typecode", title:csms_lang.public_typecode, sortable: true, width: 80, align: 'center', hidden: true },// '字典分类'
         { field: "Itemvalue", title:csms_lang.public_itemvalue, sortable: true, width: 80, align: 'center' },// '字典编码'
         { field: "Itemname", title:csms_lang.public_lable_repairquestion_cname , sortable: true, width: 150, align: 'center' },//'中文名称'
         { field: "Name_en", title: csms_lang.public_lable_repairquestion_ename, sortable: true, width: 80, align: 'center',hidden: true },//'英文名称'
          {
              field: "Isdeleted", title: csms_lang.public_lable_status, sortable: true, width: 40, align: 'center',hidden: true, formatter: function (value, rec) {//'状态'
                  if (value == "1")
                      return "<div class='helper-font-16'><i title="+	csms_lang.public_disable+" class='icofont-ban-circle color-red'></i></div>";//'停用'
                  else
                      return "<div class='helper-font-16'><i title="+	csms_lang.public_available+" class='icofont-ok-circle color-green'></i></div>";
              }
          },
         { field: "Remark", title: csms_lang.public_lable_remark, sortable: true, width: 150, align: 'center',hidden: true }
            ]];

            $(document).ready(function () {
                //关闭
                $("#btnclose").click(function (evt) { evt.preventDefault(); parent.closeDialog(); return false; });
                //保存
                $("#btnok").click(function (evt) {
                    evt.preventDefault();
                    var jsondata = [];

                    var selectedRows = $("#datagrid").datagrid("getSelections");

                    if(selectedRows.length==0){
                        $.messager.alert(csms_lang.message_info_title,csms_lang.message_please_select_row);
                        return;
                    }
                    if(singleselect){
                        parent.eval(callback + "('" + JSON.stringify(selectedRows[0]) + "')");
                    }else{
                        parent.eval(callback + "('" + JSON.stringify(selectedRows) + "')");
                    }
                    parent.closeDialog();
                });
                //查询
                $("#btnquery").click(function (evt) {
                    evt.preventDefault();
                    var params = $("#datagrid").datagrid('options').queryParams;
                    params.typecode=typecode;
                    params.s = $("#searchkey").val();
                    $("#datagrid").datagrid("load");
                    $("#datagrid").datagrid("clearSelections");
                });            

                $("#searchkey").keydown(function (event) {
                    if (event.keyCode == $.ui.keyCode.ENTER) {
                        event.preventDefault();
                        $("#btnquery").click();
                        return false;
                    }
                });

                loadTreeData();
                var node = $("#tabletree").tree("getSelected");
                if (node != null)
                    typecode = node.id;
                LoadDatagrid();
            });

            function loadTreeData()
            {
                //数据表
                $("#tabletree").tree({
                    data: tableJson,
                    onClick: function (node) {
                        typecode = node.id;
                        $("#btnquery").click();
                    }
                });
            }
            //加载列表数据
            function LoadDatagrid() {
                var $dg = $("#datagrid");
                $dg.datagrid({
                    //title: '子项目字典',
                    url: baseurl + 'Public/DictItemJson',
                    fit: true,
                    fitColumns: true,
                    striped: true,
                    nowrap: true,
                    idField: 'Id',
                    pagination: true,
                    pageNumber: 1,
                    pageSize: 100,
                    pageList: [10, 20, 30, 50, 80, 100],
                    rownumbers: true,
                    singleSelect: singleselect,
                    queryParams: {
                        typecode:"",
                        s: $("#Id").val(),
                        isdelete:""
                    },
                    sortName: 'Sort',
                    sortOrder: 'asc',
                    columns: cols,
                    onLoadSuccess: function () {
                        //多选时，加载完成后清除所有选中项（不然可能会有残留选中项）
                        //$dg.datagrid("clearSelections");
                    },
                    onDblClickRow: function (rowIndex, row) {
                        if(singleselect){
                            $("#btnok").click();
                        }
                    },
                    //onSelect: function (rowIndex, row) {
                    //    var selectedRows = $dg.datagrid("getSelections");
                    //    if (selectedRows.length == 0) {
                    //        $("#btnok").attr("disabled", true);
                    //    } else {
                    //        $("#btnok").attr("disabled", false);
                    //    }
                    //},
                    //onUnselect: function (rowIndex, row) {
                    //    var selectedRows = $dg.datagrid("getSelections");
                    //    if (selectedRows.length == 0) {
                    //        $("#btnok").attr("disabled", true);
                    //    } else {
                    //        $("#btnok").attr("disabled", false);
                    //    }
                    //}
                });
                //PaginationInit();
            }
        </script>
    }











